package com.gs.synedocket.presenter;

import com.google.gson.reflect.TypeToken;
import com.gs.synedocket.apiresult.ApiResultData;
import com.gs.synedocket.db.entity.Docket;
import com.gs.synedocket.model.SyncModel;
import com.gs.synedocket.model.listener.OnResultListener;
import com.gs.synedocket.view.ISyncDownload;

import java.util.List;

public class SyncDownloadPresenter extends BasePresenter<ISyncDownload> {
    private final SyncModel syncModel = new SyncModel();

    public void syncModel(String mapKey, String json,String postTruckNo) {
        syncModel.syncDocket(json, new OnResultListener() {
            @Override
            public void onSuccess(Object apiResult) {
                if (getView() != null) {
                    getView().onSyncDocketSuccess((ApiResultData<List<Docket>>) apiResult, mapKey,postTruckNo);
                }
            }

            @Override
            public void onFails(Exception e) {
                if (getView() != null) {
                    getView().onSyncDocketFails(e);
                }
            }
        }, new TypeToken<ApiResultData<List<Docket>>>() {
        }.getType());
    }
}
